<template>
    <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from '../../dashboard/mixins/resize'

const animationDuration = 6000

export default {
    mixins: [resize],
    props: {
        className: {
            type: String,
            default: 'chart'
        },
        width: {
            type: String,
            default: '100%'
        },
        height: {
            type: String,
            default: '300px'
        }
    },
    data() {
        return {
            chart: null
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.initChart()
        })
    },
    beforeDestroy() {
        if (!this.chart) {
            return
        }
        this.chart.dispose()
        this.chart = null
    },
    methods: {
        initChart() {
            this.chart = echarts.init(this.$el, 'macarons')


            let data = ['01周', ' 02周', ' 03周', ' 04周', ' 05周', ' 06周', ' 07周', ' 08周', ' 09周', ' 10周', ' 11周', ' 12周', ' 13周', ' 14周']

            let option = {
                tooltip: {
                    trigger: 'axis'
                },
                grid: {
                    left: '3%',
                    right: '3%',
                    bottom: 30,
                    top: 10,
                    containLabel: true
                },
                legend: {
                    bottom: 0,
                    itemWidth: 20,
                    itemHeight: 10,
                    data: ['2023年', '2024年', '2025年', '2026年'],
                    textStyle: {
                        color: '#242424',
                        fontSize: 12
                    }
                },
                xAxis: {
                    type: 'category',
                    data: data,
                    axisLabel: {
                        // rotate: 320,//坐标轴字体颜色
                        textStyle: {
                            color: '#242424',
                            fontSize: 12
                        }
                    },
                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: '#242424'
                        }
                    },
                    axisTick: {       //y轴刻度线
                        show: false
                    },
                    splitLine: {    //网格
                        show: false
                    },
                    boundaryGap: false
                },
                yAxis: {
                    type: 'value',
                    axisLabel: {        //坐标轴字体颜色
                        textStyle: {
                            color: '#3E3E3E',
                            fontSize: 12
                        }
                    },
                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: '#242424'
                        }
                    },
                    axisTick: {       //y轴刻度线
                        show: false
                    },
                    splitLine: {    //网格
                        show: false
                    }
                },

                series: [
                    {
                        name: '2023年',
                        type: 'line',
                        smooth: true,
                        symbol: 'circle',
                        symbolSize: 8,
                        itemStyle: {
                            color: '#ff9f7f',
                            borderColor: '#fff',
                            borderWidth: 2
                        },
                        lineStyle: {
                            normal: {
                                color: '#ff9f7f'

                            }
                        },
                        areaStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(52,99,254,0.52)'
                                }, {
                                    offset: 1,
                                    color: 'rgba(52,99,254,0.52)'
                                }])
                            }
                        },
                        data: [90, 152, 159, 194, 149, 183, 132, 60, 75, 169, 183, 142, 70, 85]
                    },
                    {
                        name: '2024年',
                        type: 'line',
                        smooth: true,
                        symbol: 'circle',
                        symbolSize: 8,
                        itemStyle: {
                            color: '#2F5FFE',
                            borderColor: '#fff',
                            borderWidth: 2
                        },
                        lineStyle: {
                            normal: {
                                color: '#2F5FFE'

                            }
                        },
                        areaStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(52,99,254,0.52)'
                                }, {
                                    offset: 1,
                                    color: 'rgba(52,99,254,0.52)'
                                }])
                            }
                        },
                        data: [80, 132, 119, 194, 129, 163, 112, 30, 45, 129, 163, 112, 30, 45]
                    },
                    {
                        name: '2025年',
                        type: 'line',
                        smooth: true,
                        symbol: 'circle',
                        symbolSize: 8,
                        itemStyle: {
                            color: '#34C7FE',
                            borderColor: '#fff',
                            borderWidth: 2
                        },
                        lineStyle: {
                            normal: {
                                color: '#34C7FE'
                            }
                        },
                        areaStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(52,199,254,0.75)'
                                }, {
                                    offset: 1,
                                    color: 'rgba(52,199,254,0.75)'
                                }])
                            }
                        },
                        data: [40, 162, 109, 164, 139, 193, 162, 130, 80, 139, 193, 162, 130, 80]
                    },
                    {
                        name: '2026年',
                        type: 'line',
                        smooth: true,
                        symbol: 'circle',
                        symbolSize: 8,
                        itemStyle: {
                            color: '#61DDAA',
                            borderColor: '#fff',
                            borderWidth: 2
                        },
                        lineStyle: {
                            normal: {
                                color: '#61DDAA'
                            }
                        },
                        areaStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(255, 208, 59, 0.75)'
                                }, {
                                    offset: 1,
                                    color: 'rgba(255, 208, 59, 0.75)'
                                }])
                            }
                        },
                        data: [30, 122, 129, 144, 119, 133, 122, 160, 60, 119, 153, 102, 110, 110]
                    }
                ],
                dataZoom: [{
                    type: 'slider',
                    show: false,
                    startValue: data.length - 14, // 展示后14个数据的索引
                    endValue: data.length // 展示全部数据
                }, {
                    type: 'inside', // 这个 dataZoom 组件是 inside 型 dataZoom 组件
                    start: 0,      // 左边在 0% 的位置。
                    end: 10       // 右边在 10% 的位置。
                }]
            };



            this.chart.setOption(option)
        }
    }
}
</script>
